/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.treater;

import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.actor.ChatModel;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.actor.ClientModel;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.exception.CodeNotExistsException;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.exception.TreaterNuloExeption;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.ClientControler;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.controller.ChatInterface;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import br.ufrn.dimap.projetodetalhadodesoftware.chatrmi.model.util.Message;

/**
 *
 * @author Jorge
 */
public class TreaterAddChat extends TreaterNotification{

    @Override
    public void treatNotification(ClientControler client, Message message) throws CodeNotExistsException , TreaterNuloExeption{
        if(message.getCode() == Message.ADD_CHAT){
            try {
                client.addChat((ChatInterface) message.getContent());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(TreaterAddChat.class.getName()).log(Level.SEVERE, null, ex);
                }
                client.guiClient.displayChatRooms(client.getListChats().iterator());
                System.out.println("addChat tetste");
            } catch (RemoteException ex) {
                Logger.getLogger(TreaterAddChat.class.getName()).log(Level.SEVERE, null, ex);
            }

        }else{
            if(next != null){
                next.treatNotification(client, message);
            }else{
                throw new CodeNotExistsException();
            }
        }
    }

}
